extends StatusInterface

var find_time:float
var confirm_time:float
var next_direction:int = 1

# 此怪物只会左右移动，并且遇到障碍物会反转
func _physics_process(delta):
	owner.move_and_slide()
	if owner.is_on_wall():
		if owner.velocity.x > 5 * owner.max_speed:
			manage_node.to_death()
		else:
			owner.direction *= -1


func _process(delta):
	owner.velocity.y += owner.gravity * delta
	owner.velocity.x = move_toward(owner.velocity.x, 0.0, owner.acceleration * delta)
	if owner.look_something() == 2:
		confirm_time += delta
		if confirm_time > 0.5:
			reset_time()
			manage_node.to_run()
			return
	else:
		
		find_time += delta
		if find_time < 2.0:
			next_direction = owner.direction
		elif find_time < 3.0:
			owner.direction = -next_direction
		elif find_time < 4.0:
			owner.direction = next_direction
		elif find_time < 5.0:
			owner.direction = -next_direction
		else:
			reset_time()
			manage_node.to_walk()
			return
	
	owner.set_face_direction(owner.direction)

func reset_time():
	confirm_time = 0
	find_time = 0
